<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据类型</title>
</head>

<body>

</body>
<script>
    // 数字类型
    var num = 10;


    // String 字符串
    var str = 'hello';


    // Boolean  布尔型
    var flag = true;
    // true
    console.log(flag);
    // 9
    console.log(8 + flag);
    // true  'boolean'
    console.log(flag, typeof flag)
    // true 'numbertrue'
    console.log(flag, typeof 8 + flag)

    var flag = false;
    console.log(8 + false);

    // 未定义类型  Undefined
    // Null  空
    // typeof   检测返回值类型

    // 十进制   0 -- 10
    // 二进制   0 -- 1
    // 八进制   0 -- 7
    // 十六进制  0 -- 9 a -- f
    var a = 0377;
    // 255
    console.log(a);

    var b = 0xff;
    // 255
    console.log(b);
    ////num.toString(进制)
    var c = 255;
    var c = c.toString(2);
    // 1111 1111
    console.log(c)

    // 1.7976931348623157e+308
    console.log(Number.MAX_VALUE);
    // 5e-324
    console.log(Number.MIN_VALUE);
    // NaN 'number'
    console.log(NaN, typeof NaN);


    // 长度获取
    var d = 'hello';
    console.log(d.length); //5

    console.log(d[0]); //h [0]索引 l

    // 字符串拼接
    var e = prompt('', [15]);
    console.log(5 + e, typeof 5 + e);// 515  number515
    e = +e;
    console.log(5 + e, typeof 5 + e);// 20  'number15'

    // 数字类型转换
    //Number()
    var f = '';
    f = Number(str);
    console.log(f, typeof f);// 0 'number'
    //parseInt()
    var i = '122.445ffgd';
    i = parseInt(i);
    console.log(i, typeof i);// 122  'number'
    // parseFloat
    var g = '122.445ffgd';
    g = parseFloat(g);
    console.log(g, typeof g);// 122.445  'number'

    //隐式转换
    var k = '123'
    console.log(k, typeof k);//123 string
    k = +k
    console.log(k, typeof k);//123 'number'

    //字符串转换
    //String(参数)  
    var l = 12;
    console.log(l,typeof l);// 12 'number'
    l = String(l);
    console.log(l,typeof l);// 12 'string'
    //参数.toString()
    var m = 12;
    console.log(m,typeof m);// 12 'number'
    m = m.toString();
    console.log(m,typeof m);// 12 'string'

    // undefined  null
    var n;
    console.log(n,typeof n);//undefined 'undefined' 
    n = String(n);
    console.log(n,typeof n);//undefined 'string'


    //Boolean转换
    console.log(Boolean(''),Boolean(0),Boolean(null),Boolean(undefined),Boolean(NaN),Boolean(false));//false false false false false false

    console.log(Boolean('  '),Boolean({}),Boolean([]));//true true true


    // isNaN()
    var z = isNaN(123);
    console.log(z); //false
    console.log(isNaN(z)); //false

    console.log(isNaN('123asd')); // true
</script>

</html>